home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2007 December
/
PCWKCD1207B.iso
/
Windows marzen
/
Maxthon 2.0.4
/
mx_2.0.4.5799.exe
/
template
/
_shared
/
js
/
maxAjaxManager.js
< prev
next >
Wrap
Text File
|
2007-09-20
|
3KB
|
142 lines
var maxAjaxManager={};
maxAjaxManager.error={};
maxAjaxManager.xmlhttp={};
maxAjaxManager.callback={};
maxAjaxManager.status={};
maxAjaxManager.result={};
maxAjaxManager.createXMLHTTP=function(id){
var _2;
try{
if(window.XMLHttpRequest){
_2=new XMLHttpRequest();
}else{
_2=new ActiveXObject("Microsoft.XMLHTTP");
}
}
catch(e){
if(id){
maxAjaxManager.error[id]={"code":e.number,"text":e.description};
}
return null;
}
return _2;
};
maxAjaxManager.get=function(id,_4,_5,_6){
return maxAjaxManager.call(id,"get",_4,_5,_6);
};
maxAjaxManager.post=function(id,_8,_9,_a,_b){
if(!_b){
_b={};
}
_b["requestString"]=_a;
return maxAjaxManager.call(id,"post",_8,_9,_b);
};
maxAjaxManager.call=function(id,_d,_e,_f,_10){
if(!_10){
_10={};
}
if(!_d){
_d="GET";
}
if(!_10["async"]){
_10["async"]=true;
}
if(!_10["responseType"]){
_10["responseType"]=0;
}
if(!_10["requestString"]){
_10["requestString"]="";
}
if((_d!="post")||(_d=="post"&&_10["requestString"]=="")){
_d="get";
}
if(!maxAjaxManager.xmlhttp[id]){
maxAjaxManager.xmlhttp[id]=maxAjaxManager.createXMLHTTP(id);
if(!maxAjaxManager.xmlhttp[id]){
return false;
}
}
maxAjaxManager.callback[id]=_f;
maxAjaxManager.xmlhttp[id].onreadystatechange=function(){
return maxAjaxManager.checkState(id,_10["responseType"]);
};
if(_10["requestHeaders"]){
for(var i=0;i<_10["requestHeaders"].length;i++){
maxAjaxManager.xmlhttp[id].setRequestHeader(_10["requestHeaders"][i][0],_10["requestHeaders"][i][1]);
}
}
try{
maxAjaxManager.xmlhttp[id].open(_d,_e,_10["async"]);
maxAjaxManager.xmlhttp[id].send(_10["requestString"]);
}
catch(e){
maxAjaxManager.error[id]={"code":e.number,"text":e.description};
return false;
}
return true;
};
maxAjaxManager.checkState=function(id,_13){
if(maxAjaxManager.xmlhttp[id].readyState!=4){
return;
}
if(_13=="xml"){
maxAjaxManager.result[id]=maxAjaxManager.xmlhttp[id].responseXML.xml;
}else{
if(_13=="stream"){
maxAjaxManager.result[id]=maxAjaxManager.xmlhttp[id].responseStream;
}else{
maxAjaxManager.result[id]=maxAjaxManager.xmlhttp[id].responseText;
}
}
maxAjaxManager.status[id]={"code":maxAjaxManager.xmlhttp[id].status,"text":maxAjaxManager.xmlhttp[id].statusText};
maxAjaxManager.callback[id](id,(maxAjaxManager.xmlhttp[id].status==200?true:false));
maxAjaxManager.xmlhttp[id].onreadystatechange=function(){
};
maxAjaxManager.xmlhttp[id]=null;
maxAjaxManager.callback[id]=null;
};
maxAjaxManager.dispose=function(id){
try{
maxAjaxManager.xmlhttp[id].abort();
maxAjaxManager.xmlhttp[id].onreadystatechange=function(){
};
maxAjaxManager.xmlhttp[id]=null;
maxAjaxManager.callback[id]=null;
maxAjaxManager.result[id]=null;
maxAjaxManager.error[id]=null;
maxAjaxManager.status[id]=null;
}
catch(e){
}
};
maxAjaxManager.cleanUp=function(){
try{
for(var id in maxAjaxManager.xmlhttp){
maxAjaxManager.xmlhttp[id].abort();
maxAjaxManager.xmlhttp[id].onreadystatechange=function(){
};
maxAjaxManager.xmlhttp[id]=null;
}
for(var id in maxAjaxManager.callback){
maxAjaxManager.callback[id]=null;
}
for(var id in maxAjaxManager.result){
maxAjaxManager.result[id]=null;
}
for(var id in maxAjaxManager.error){
maxAjaxManager.error[id]=null;
}
for(var id in maxAjaxManager.status){
maxAjaxManager.status[id]=null;
}
}
catch(e){
}
};
if(window.attachEvent){
window.attachEvent("onunload",maxAjaxManager.cleanUp);
}else{
window.addEventListener("unload",maxAjaxManager.cleanUp,false);
}